﻿package plugin.component.view
{
    import __AS3__.vec.*;
    import com.core.*;
    import com.sh.game.display.*;
    import flash.display.*;
    import flash.utils.*;
    import plugin.component.*;
    import plugin.component.view.enum.*;

    public class RoleShow extends Sprite
    {
        public var _nameLayer:Sprite;
        private var _manager:SimpleRoleManager;
        private var _model:String = "";
        private var _allMovies:Dictionary;
        private var _handModel:String = null;
        private var _bodyModel:String = null;
        private var _wingModel:String = null;
        private var _weaponEffectModel:String = null;
        private var _weaponEfftype:int = 1;
        private var _armEffectModel:String = null;
        private var _petModel:String = null;
        private var _fashions:Object = null;
        private var _actVec:Vector.<ActorMovie>;
        private var _allacttVec:Vector.<ActorMovie>;
        private var _wing:Object;
        private var _fashionCfg:Object;
        private var _armEfftype:int = 1;
        private var _weaponEffDic:Object;
        private var _weaponmc:BMDMovieClip;
        private var _effScale:Number = 1;
        private var _sex:int = 0;
        public var updatefunc:Function;

        public function RoleShow(param1:String, param2:int, param3:Object, param4:Object, param5:Object)
        {
            this._allMovies = new Dictionary();
            this._actVec = new Vector.<ActorMovie>;
            this._allacttVec = new Vector.<ActorMovie>;
            this._model = param1;
            this._fashions = param5;
            while (this._actVec.length > 0)
            {
                
                this._actVec.pop();
            }
            while (this._allacttVec.length > 0)
            {
                
                this._allacttVec.pop();
            }
            this._sex = param2;
            this.initArmsModel(param3, param5, param4);
            if (this._handModel == "" || this._handModel == null)
            {
                if (this._sex == 1)
                {
                    this._handModel = "101";
                }
                else if (this._sex == 0)
                {
                    this._handModel = "100";
                }
            }
            if (this._bodyModel == "" || this._bodyModel == null)
            {
                if (this._sex == 1)
                {
                    this._bodyModel = "1";
                }
                else if (this._sex == 0)
                {
                    this._bodyModel = "0";
                }
                else
                {
                    this._bodyModel = this._model;
                }
            }
            this.updateWing(param4);
            if (this._sex == 2)
            {
                this._allacttVec.push(new ActorMovie(this, this._bodyModel, McType.Closeth, true));
            }
            else
            {
                this._allacttVec.push(new ActorMovie(this, this._bodyModel, McType.Closeth));
            }
            this._allacttVec.push(new ActorMovie(this, this._handModel, McType.hand));
            return;
        }// end function

        private function TypeToModel(param1:int) : String
        {
            var _loc_2:String = "";
            switch(param1)
            {
                case McType.Wing:
                {
                    _loc_2 = this._wingModel;
                    break;
                }
                case McType.Closeth:
                {
                    _loc_2 = this._bodyModel;
                    break;
                }
                case McType.hand:
                {
                    _loc_2 = this._handModel;
                    break;
                }
                case McType.EffCloseth:
                {
                    _loc_2 = this._armEffectModel;
                    break;
                }
                case McType.Effhand:
                {
                    _loc_2 = this._weaponEffectModel;
                    break;
                }
                case McType.Pet:
                {
                    _loc_2 = this._petModel;
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return _loc_2;
        }// end function

        public function updateshow(param1:int, param2:Object, param3:Object, param4:Object) : void
        {
            this._armEffectModel = null;
            this._weaponEffectModel = null;
            this._handModel = null;
            this._wingModel = null;
            this._petModel = null;
            this._bodyModel = null;
            this._sex = param1;
            this._fashions = param4;
            this.initArmsModel(param2, param4, param3);
            if (this._handModel == "" || this._handModel == null)
            {
                if (this._sex == 1)
                {
                    this._handModel = "101";
                }
                else
                {
                    this._handModel = "100";
                }
            }
            if (this._bodyModel == "" || this._bodyModel == null)
            {
                if (this._sex == 1)
                {
                    this._bodyModel = "1";
                }
                else
                {
                    this._bodyModel = "0";
                }
            }
            var _loc_5:int = 0;
            while (_loc_5 < this._allacttVec.length)
            {
                
                this._allacttVec[_loc_5].updatemodel(this.TypeToModel(this._allacttVec[_loc_5]._mctype));
                _loc_5++;
            }
            return;
        }// end function

        public function updateModel(param1:String, param2:Object = null) : void
        {
            if (this._model == param1)
            {
                return;
            }
            this._model = param1;
            this._allacttVec[0].updatemodel(this._model);
            if (param2)
            {
                this.updateshow(this._sex, param2, this._wing, this._fashions);
            }
            return;
        }// end function

        public function doAction(param1:int) : void
        {
            this._allacttVec[0].doAction(param1);
            return;
        }// end function

        public function updateWing(param1:Object) : void
        {
            var _loc_3:ActorMovie = null;
            var _loc_2:String = null;
            this._wing = param1;
            if (param1)
            {
                this._wingModel = this.getWingModel(param1);
                _loc_3 = new ActorMovie(this, this._wingModel, McType.Wing);
                this._allacttVec.push(_loc_3);
            }
            return;
        }// end function

        public function addMovie(param1:ActorMovie) : void
        {
            var _loc_5:int = 0;
            var _loc_2:int = 0;
            var _loc_3:Boolean = false;
            var _loc_4:Boolean = true;
            while (_loc_4)
            {
                
                _loc_4 = false;
                _loc_2 = 0;
                while (_loc_2 < this._actVec.length)
                {
                    
                    if (this._actVec[_loc_2]._mctype == param1._mctype || this._actVec[_loc_2]._mc == null)
                    {
                        this._actVec.splice(_loc_2, 1);
                        _loc_4 = true;
                        break;
                    }
                    _loc_2++;
                }
            }
            _loc_2 = 0;
            while (_loc_2 < this._actVec.length)
            {
                
                if (this._actVec[_loc_2]._mctype > param1._mctype)
                {
                    _loc_5 = this.getChildIndex(this._actVec[_loc_2]._mc);
                    param1.UpdateIndex(_loc_5);
                    _loc_3 = true;
                    break;
                }
                _loc_2++;
            }
            if (_loc_3)
            {
                this._actVec.splice(_loc_2, 0, param1);
            }
            else
            {
                this._actVec.push(param1);
            }
            this.locationArmEff();
            return;
        }// end function

        private function armEffCfgLoaded(param1:Object) : void
        {
            this._weaponEffDic = param1;
            this.locationArmEff();
            return;
        }// end function

        private function locationArmEff(param1:int = -1) : void
        {
            var _loc_3:Object = null;
            var _loc_4:BMDMovieClip = null;
            var _loc_5:BMDMovieClip = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_2:* = ActionType.SHOWSTAND;
            var _loc_6:int = 0;
            while (_loc_6 < this._allacttVec.length)
            {
                
                if (this._allacttVec[_loc_6]._mctype == McType.hand)
                {
                    _loc_4 = this._allacttVec[_loc_6]._mc;
                }
                else if (this._allacttVec[_loc_6]._mctype == McType.Effhand)
                {
                    _loc_5 = this._allacttVec[_loc_6]._mc;
                }
                _loc_6++;
            }
            if (this._weaponEffDic && _loc_4 && _loc_5)
            {
                _loc_3 = this._weaponEffDic[_loc_2 + "_" + 4 + "_" + _loc_4.frame];
                if (_loc_3)
                {
                    _loc_7 = 1;
                    if (_loc_4.scaleX == -1)
                    {
                        _loc_7 = -1;
                    }
                    _loc_5.x = int(_loc_3.x) * _loc_7;
                    _loc_5.y = int(_loc_3.y);
                    if (_loc_5)
                    {
                        _loc_5.scaleX = Number(_loc_3.scaleX) * _loc_7 * this._effScale;
                        _loc_5.scaleY = _loc_3.scaleY * this._effScale;
                        _loc_8 = 0;
                        if (_loc_7 < 0)
                        {
                            _loc_8 = -_loc_3.rotation;
                        }
                        else
                        {
                            _loc_8 = _loc_3.rotation;
                        }
                        _loc_5.rotation = _loc_8;
                    }
                }
            }
            else if (!_loc_4 && _loc_5)
            {
                _loc_5.scaleX = 0;
                _loc_5.scaleY = 0;
            }
            return;
        }// end function

        public function getWingModel(param1) : String
        {
            if (param1 > 100)
            {
                return param1;
            }
            var _loc_2:* = int(param1);
            var _loc_3:String = null;
            var _loc_4:* = ConfigDictionary.data.wing;
            if (ConfigDictionary.data.wing[_loc_2])
            {
                _loc_3 = _loc_4[_loc_2].model;
            }
            return _loc_3;
        }// end function

        public function initArmsModel(param1:Object, param2:Object, param3:Object) : void
        {
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            var _loc_4:* = ModelProxy.getValue("data", "option");
            for each (_loc_5 in ArmPosType.roleArms)
            {
                
                _loc_6 = ArmPosType.armToFashionPos(_loc_5);
                _loc_7 = this.getFashion(_loc_6);
                _loc_8 = null;
                if (param1 && param1[_loc_5] != null)
                {
                    _loc_8 = param1[_loc_5];
                }
                if (_loc_8 == null && _loc_7 < 0)
                {
                    continue;
                }
                switch(_loc_5)
                {
                    case ArmPosType.PosWeapon:
                    {
                        if (_loc_7 >= 0)
                        {
                            this._handModel = _loc_7 + "";
                        }
                        else if (_loc_8)
                        {
                            this._handModel = this.getArmModel(_loc_8);
                            this._weaponEffectModel = this.getArmEffect(_loc_8);
                            this._weaponEfftype = _loc_8.efftype;
                        }
                        break;
                    }
                    case ArmPosType.PosClothes:
                    {
                        if (_loc_7 >= 0)
                        {
                            this._bodyModel = _loc_7 + "";
                        }
                        else if (_loc_8)
                        {
                            this._bodyModel = this.getArmModel(_loc_8);
                            this._armEffectModel = this.getArmEffect(_loc_8, true);
                            this._armEfftype = _loc_8.efftype;
                        }
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            this._petModel = this.getFashion(5) + "";
            if (_loc_4 && _loc_4.showwing == 0)
            {
                return;
            }
            if (param3)
            {
                this._wingModel = this.getWingModel(param3);
            }
            return;
        }// end function

        private function getFashion(param1:int) : int
        {
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_2:int = -1;
            if (this._fashions)
            {
                if (!this._fashionCfg)
                {
                    this._fashionCfg = ConfigDictionary.data.fashion;
                }
                if (this._fashions[param1] > 0)
                {
                    if (this._fashionCfg[this._fashions[param1]].model is Array)
                    {
                        _loc_2 = this._fashionCfg[this._fashions[param1]].model[this._sex];
                    }
                    else
                    {
                        _loc_2 = this._fashionCfg[this._fashions[param1]].model;
                    }
                }
                else if (param1 == ArmPosType.FPosHead)
                {
                    _loc_4 = this._fashions[ArmPosType.FPosClothes];
                    if (this._fashionCfg[_loc_4])
                    {
                        _loc_5 = this._fashionCfg[_loc_4].headmodel;
                        if (_loc_5 >= 0)
                        {
                            _loc_2 = _loc_5;
                        }
                    }
                }
            }
            return _loc_2;
        }// end function

        public function initArmsModel2(param1:Object) : void
        {
            var _loc_2:Object = null;
            for each (_loc_2 in param1)
            {
                
                if (_loc_2 == null)
                {
                    continue;
                }
                switch(int(_loc_2.cls))
                {
                    case ArmPosType.PosWeapon:
                    {
                        this._handModel = this.getArmModel(_loc_2);
                        this._weaponEffectModel = this.getArmEffect(_loc_2);
                        this._weaponEfftype = _loc_2.efftype;
                        break;
                    }
                    case ArmPosType.PosClothes:
                    {
                        this._bodyModel = this.getArmModel(_loc_2);
                        this._armEffectModel = this.getArmEffect(_loc_2, true);
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            return;
        }// end function

        public function getArmModel(param1:Object) : String
        {
            var _loc_2:* = (param1.model + "").split("/");
            if (_loc_2.length == 2)
            {
                if (this._sex == 1)
                {
                    return _loc_2[1];
                }
                return _loc_2[0];
            }
            return param1.model;
        }// end function

        public function getArmEffect(param1:Object, param2:Boolean = false) : String
        {
            var _loc_3:Array = null;
            if (param1.effect && param1.effect != "")
            {
                _loc_3 = String(param1.effect).split("/");
                if (_loc_3.length == 2)
                {
                    if (param1.superlevel >= 10)
                    {
                        if (_loc_3[1] != "0")
                        {
                            return _loc_3[1];
                        }
                        return null;
                    }
                    else if (!param1.hasOwnProperty("superlevel") || param1.superlevel >= 0)
                    {
                        if (_loc_3[0] != "0")
                        {
                            return _loc_3[0];
                        }
                        return null;
                    }
                    if (param1.yitian == 1)
                    {
                        return _loc_3[0];
                    }
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
            return null;
        }// end function

        public function destroy() : void
        {
            var _loc_1:ActorMovie = null;
            while (this._actVec.length > 0)
            {
                
                this._actVec.pop();
            }
            while (this._allacttVec && this._allacttVec.length > 0)
            {
                
                _loc_1 = this._allacttVec.pop();
                _loc_1.dispose();
                _loc_1 = null;
            }
            this._armEffectModel = null;
            this._weaponEffectModel = null;
            this._handModel = null;
            this._bodyModel = null;
            this._wingModel = null;
            this._petModel = null;
            return;
        }// end function

    }
}
